package app.action;

import java.awt.event.ActionEvent;
import java.awt.event.MouseEvent;
import java.awt.event.MouseListener;
import java.awt.event.MouseMotionListener;

import app.ui.AbsCommonPanel;
import app.ui.MP3PlayerUi;

public class MouseAction extends AbsCommonPanelAction implements
		MouseMotionListener, MouseListener {

	private MP3PlayerUi mPanel;

	protected int xOld = 0, yOld = 0;
	protected int frameX = 0, frameY = 0;

	public MouseAction(AbsCommonPanel absCommonPanel) {
		super(absCommonPanel);
	}

	@Override
	public void mouseDragged(MouseEvent e) {

		// If the frame does change the position then delta X & delta Y does not
		// change also.
		// We want this change follow the mouse so, delta X & delta Y have to
		// change with deviation equal to deviation of mouse changing.
		doMoving(e);
	}

	@Override
	public void mouseMoved(MouseEvent e) {
		// TODO Auto-generated method stub

	}

	@Override
	public void actionPerformed(ActionEvent e) {

	}

	@Override
	protected void doCatenation() {
		mPanel = (MP3PlayerUi) absCommonPanel;
	}

	@Override
	public void mouseClicked(MouseEvent e) {
	}

	@Override
	public void mousePressed(MouseEvent e) {
		xOld = e.getX();
		yOld = e.getY();

		frameX = mPanel.getmFrame().getX();
		frameY = mPanel.getmFrame().getY();
	}

	@Override
	public void mouseReleased(MouseEvent e) {
	}

	@Override
	public void mouseEntered(MouseEvent e) {
		// TODO Auto-generated method stub

	}

	@Override
	public void mouseExited(MouseEvent e) {
		// TODO Auto-generated method stub

	}

	protected void doMoving(MouseEvent e) {
		frameX += e.getX() - xOld;
		frameY += e.getY() - yOld;
		mPanel.getmFrame().setLocation(frameX, frameY);

		System.out.println(mPanel.getmFrame().getLocation());
	}

}
